<?php
// 本类由系统自动生成，仅供测试用途
class IndexAction extends Action {
	private $root_name = "";
	private $site_root = '';
	private $file_noexist = 'file_noexist';
	private $dele_statice_success = 'dele_statice_success';
	private $dele_statice_fail = 'dele_statice_fail';
	private $delete_success = 'delete_success';
	private $delete_fail = 'delete_fail';
	private $statice_success = 'statice_success';
	private $statice_fail = 'staice_fail';
	private $pro_no_statice_name = 'pro_no_statice_name';
	private $art_no_statice_name = 'art_no_statice_name';
	private $howto_no_statice_name = 'howto_no_statice_name';
	private $plate_no_statice_name = 'plate_no_statice_name';
	public function __construct() {
		$this->root_name = 'http://' . $_SERVER ['HTTP_HOST'] . '/index.php';
		$this->site_root = 'http://' . $_SERVER ['HTTP_HOST'];
		parent::__construct ();
	}
	public function index() {
		header ( "Content-Type:text/html; charset=utf-8" );
		
		// $this->display('skin@index:index');//跨皮肤
		// $this->display('login');
		$system = M ( 'System' );
		$sdata = $system->find ();
		$this->assign ( 'use_yzm', $sdata ['use_yzm'] );
		if (! isset ( $_SESSION ['login_name'] ) || ! isset ( $_COOKIE ['login_name'] )) {
			if (isset ( $_POST ['sub'] )) {
				if (md5 ( $_POST ['username'] ) != "97ca5e106095427b77f81346a540398e") {
					$this->assign ( 'err_username', '1' );
					$this->display ();
					return;
				}
				if (md5 ( $_POST ['password'] ) != '9c5122e901bb82ae47e5ed0ce84d8a44') {
					$this->assign ( 'err_password', '1' );
					$this->display ();
					return;
				}
				if (isset ( $_POST ['verify'] ) && $_SESSION ['verify'] != md5 ( $_POST ['verify'] )) {
					$this->assign ( 'err_yzm', '1' );
					$this->display ();
					return;
				}
				setcookie ( 'login_name', $_POST ['username'] );
				session_start ();
				$_SESSION ['login_name'] = $_POST ['username'];
				$this->display ( 'system' );
			} else {
				$this->display ();
			}
		} else {
			$this->display ( 'system' );
		}
	}
	Public function verify() {
		import ( "ORG.Util.Image" );
		Image::buildImageVerify ();
	}
	public function system_info() {
		$system = M ( 'System' );
		$s = $system->select ();
		if ($s) {
			$this->assign ( 'is_exit', 1 );
		}
	}
	
	// 判断是否登陆
	private function is_login() {
		header ( "Content-Type:text/html; charset=utf-8" );
		if (! isset ( $_SESSION ['login_name'] ) || ! isset ( $_COOKIE ['login_name'] )) {
			// $this->display('index');
			echo "<script>location.href='" . __URL__ . "/index';</script>";
			exit ();
		}
		$this->system_info ();
	}
	// 进入系统参数页面
	public function system() {
		$this->is_login ();
		$this->display ();
	}
	// 设置系统全局参数
	public function set_system() {
		$this->is_login ();
		if ($this->isPost ()) {
			$system = M ( 'System' );
			if ($system->create ()) {
				if ($system->add ( $_POST )) {
					echo "<script>alert('添加成功');history.back();</script>";
				} else {
					echo "<script>alert('添加失败');history.back();</script>";
				}
			} else {
				echo "<script>alert('创建失败');history.back();</script>";
				return;
			}
		} else {
			$this->display ();
		}
	}
	public function modify_system() {
		$this->is_login ();
		if ($this->isPost ()) {
			$system = M ( 'System' );
			
			$id = isset ( $_POST ['s_id'] ) ? $_POST ['s_id'] : 0;
			if (! $id) {
				return;
			}
			if ($system->where ( "id=" . $id )->save ( $_POST )) {
				echo "<script>alert('修改成功');history.back();</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$s = M ( "System" );
			$data = $s->find ();
			$this->assign ( 'sdata', $data );
			$this->display ();
		}
	}
	// 添加一级分类
	public function big_category() {
		$this->is_login ();
		if ($this->isPost ()) {
			$bigcategory = M ( 'Bigcategory' );
			$_POST ['add_time'] = time ();
			if (! $_POST ['big_category_name']) {
				return;
			}
			if ($bigcategory->where ( "big_category_name='" . $_POST ['big_category_name'] . "'" )->find ()) {
				echo "<script>alert('分类名已存在，请填写其他分类名');history.back();</script>";
				return;
			}
			if (! $_FILES) {
				return;
			}
			$updata = $this->up ();
			if ($updata) {
				$_POST ['big_img'] = $updata [0] ['savename'];
			} else {
				echo "<script>alert('上传失败');history.back();</script>";
				return;
			}
			if ($bigcategory->add ( $_POST )) {
				echo "<script>alert('添加成功');history.back();</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$this->display ();
		}
	}
	// 添加栏目
	public function plate() {
		$this->is_login ();
		if ($this->isPost ()) {
			$plate = M ( 'Plate' );
			// $data['plate_name']=isset($_POST['plate_name'])?trim($_POST['plate_name']):'';
			$insert ['plate_name'] = isset ( $_POST ['plate_name'] ) ? trim ( $_POST ['plate_name'] ) : '';
			$insert ['plate_title'] = isset ( $_POST ['plate_title'] ) ? trim ( $_POST ['plate_title'] ) : '';
			$insert ['pid'] = isset ( $_POST ['pid'] ) ? trim ( $_POST ['pid'] ) : 0;
			$insert ['plate_keyword'] = isset ( $_POST ['plate_keyword'] ) ? trim ( $_POST ['plate_keyword'] ) : 0;
			$insert ['statice_name'] = isset ( $_POST ['statice_name'] ) ? trim ( $_POST ['statice_name'] ) : '';
			$insert ['win_mac_classfy'] = isset ( $_POST ['win_mac_classfy'] ) ? trim ( $_POST ['win_mac_classfy'] ) : '1';
			$insert ['plate_description'] = isset ( $_POST ['plate_dis'] ) ? trim ( $_POST ['plate_dis'] ) : '';
			$insert ['add_time'] = time ();
			if (! $insert ['plate_name'] || ! $insert ['pid']) {
				return;
			}
			if ($plate->where ( "pid=" . $insert ['pid'] . " and plate_name='" . $insert ['plate_name'] . "'" )->find ()) {
				echo "<script>alert('栏目名已存在，请填写其他栏目名');history.back();</script>";
				return;
			}
			/*
			 * $ret=true; $explode=explode(';', $data['plate_name']);
			 * foreach($explode as $k => $v){ $insert['plate_name']=$v;
			 * if(!$plate->add($insert)){ $ret=false; } }
			 */
			if ($plate->add ( $insert )) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/plate_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$bigcategory = M ( 'Bigcategory' );
			$cate = $bigcategory->select ();
			$this->assign ( 'cate', $cate );
			$this->display ();
		}
	}
	// 添加产品
	public function product() {
		$this->is_login ();
		if ($this->isPost ()) {
			$product = M ( 'Product' );
			
			$_POST ['relative_product'] = isset ( $_POST ['rp'] ) ? trim ( $_POST ['rp'], ',' ) : '';
			if (get_magic_quotes_gpc ()) {
				$_POST ['content'] = isset ( $_POST ['product_content'] ) ? stripslashes ( $_POST ['product_content'] ) : '';
				$_POST ['sec_description'] = isset ( $_POST ['sec_description'] ) ? stripslashes ( $_POST ['sec_description'] ) : '';
			} else {
				$_POST ['content'] = $_POST ['product_content'];
			}
			$_POST ['add_time'] = time ();
			$width = isset ( $_POST ['width'] ) ? trim ( $_POST ['width'] ) : 0;
			$height = isset ( $_POST ['height'] ) ? trim ( $_POST ['height'] ) : 0;
			if (! $_POST ['product_name']) {
				return;
			}
			if ($product->where ( "pid=" . $_POST ['pid'] . " and product_name='" . $_POST ['product_name'] . "'" )->find ()) {
				echo "<script>alert('产品名已存在，请填写其他产品名');history.back();</script>";
				return;
			}
			if (! $_FILES) {
				return;
			}
			$updata = $this->up ( $width, $height );
			
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 't_img') {
						$_POST ['product_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'sec_img') {
						$_POST ['sec_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'three_img') {
						$_POST ['three_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'pimg') {
						$_POST ['pimg'] = $v ['savename'];
					} elseif ($v ['key'] == 'small_icon') {
						$_POST ['small_icon'] = $v ['savename'];
					}
				}
			} else {
				echo "<script>alert('上传失败');history.back();</script>";
				return;
			}
			if ($product->data ( $data )->add ()) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/product_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$product = M ( 'Product' );
			$bigcategory = M ( 'Bigcategory' );
			$cate = $bigcategory->select ();
			$this->assign ( 'cate', $cate );
			$plate = M ( 'Plate' );
			$plate = $plate->select ();
			$this->assign ( 'plate', $plate );
			
			$allpro = $product->field ( 'think_product.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_product.pid' )->order ( 'b.id' )->select ();
			
			$this->assign ( 'allpro', $allpro );
			
			$art_classify = M ( "ArticleClassify" );
			$ac_data = $art_classify->field ( 'think_article_classify.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->select ();
			$this->assign ( 'ac_data', $ac_data );
			$this->display ();
		}
	}
	
	// 上传文件
	private function up($width = 0, $height = 0) {
		$width = $width == 0 ? '150' : $width;
		$height = $height == 0 ? '100' : $height;
		import ( '@.Org.UploadFile' );
		$upload = new UploadFile ();
		$upload->maxSize = '1000000'; // 是指上传文件的大小，默认为-1,不限制上传文件大小bytes
		$upload->savePath = './Public/upload/'; // 上传保存到什么地方？路径建议大家已主文件平级目录或者平级目录的子目录来保存
		$upload->saveRule = uniqid; // 上传文件的文件名保存规则 time uniqid com_create_guid
		                            // uniqid
		                            // $upload->autoCheck=false ; //是否自动检测附件
		$upload->uploadReplace = true; // 如果存在同名文件是否进行覆盖
		$upload->allowExts = array (
				'jpg',
				'jpeg',
				'png',
				'gif' 
		); // 准许上传的文件后缀
		$upload->allowTypes = array (
				'image/png',
				'image/jpg',
				'image/pjpeg',
				'image/gif',
				'image/jpeg' 
		); // 检测mime类型
		$upload->thumb = true; // 是否开启图片文件缩略
		$upload->thumbMaxWidth = $width; // 以字串格式来传，如果你希望有多个，那就在此处，用,分格，写上多个最大宽
		$upload->thumbMaxHeight = $height; // 最大高度
		$upload->thumbPrefix = 's_,m_'; // 缩略图文件前缀
		                                // $upload->thumbSuffix='_s,_m'; //文件后缀
		                                // $upload->thumbPath='' ; // 如果留空直接上传至
		                                // $upload->thumbFile 在数据库当中也存一个文件名即可
		$upload->thumbRemoveOrigin = 0; // 如果生成缩略图，是否删除原图 1是0否
		                                // $upload->autoSub 是否使用子目录进行保存上传文件
		                                // $upload->subType='' 子目录创创方式默认为hash
		                                // 也可以设为date
		                                // $upload->dateFormat 子目录方式date的指定日期格式
		                                // $upload->hashLevle
		
		if (! $upload->upload ()) { // 上传错误 提示错误信息
		                            
			// $this->error($upload->getErrorMsg());
			return false;
		} else { // 上传成功 获取上传文件信息
			
			return $upload->getUploadFileInfo ();
		}
	}
	
	// 添加文章
	public function article() {
		$this->is_login ();
		if ($this->isPost ()) {
			$article = M ( 'Article' );
			if (get_magic_quotes_gpc ()) {
				$_POST ['content'] = isset ( $_POST ['content'] ) ? stripslashes ( $_POST ['content'] ) : '';
				$_POST ['author_des'] = isset ( $_POST ['author_des'] ) ? stripslashes ( $_POST ['author_des'] ) : '';
			}
			$_POST ['add_time'] = time ();
			$updata = $this->up ( 0, 0 );
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 'author_img') {
						$_POST ['author_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'right_img') {
						$_POST ['right_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'small_icon') {
						$_POST ['small_icon'] = $v ['savename'];
					}
				}
			}
			if (! $_POST ['title']) {
				return;
			}
			if ($article->where ( "pid=" . $_POST ['pid'] . " and title='" . $_POST ['title'] . "'" )->find ()) {
				echo "<script>alert('文章标题已存在，请填写其他文章标题');history.back();</script>";
				return;
			}
			if ($article->add ( $_POST )) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/article_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$bigcategory = M ( 'Bigcategory' );
			$cate = $bigcategory->select ();
			$this->assign ( 'cate', $cate );
			$art_classify = M ( "ArticleClassify" );
			$ac_data = $art_classify->field ( 'think_article_classify.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->select ();
			$this->assign ( 'ac_data', $ac_data );
			$this->display ();
		}
	}
	// 添加产品多个链接
	public function product_download_link() {
		$this->is_login ();
		if ($this->isPost ()) {
			$pdl = M ( 'ProductDownloadLink' );
			$insert ['name'] = isset ( $_POST ['name'] ) ? trim ( $_POST ['name'] ) : '';
			$insert ['url'] = isset ( $_POST ['url'] ) ? trim ( $_POST ['url'] ) : '';
			$insert ['pid'] = isset ( $_POST ['pid'] ) ? intval ( $_POST ['pid'] ) : 0;
			if (! $insert ['url'] || ! $insert ['pid']) {
				return;
			}
			if ($pdl->where ( "pid=" . $insert ['pid'] . " and name='" . $insert ['name'] . "'" )->find ()) {
				echo "<script>alert('下载链接名已存在，请填写其他名字');history.back();</script>";
				return;
			}
			if ($pdl->add ( $insert )) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/product_download_link_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$p = M ( 'Product' );
			$cate = $p->where ( "one_download_link=0" )->select ();
			$this->assign ( 'pdata', $cate );
			$this->display ();
		}
	}
	// 产品多链接管理
	public function product_download_link_manage() {
		$this->is_login ();
		$pdl = M ( 'ProductDownloadLink' );
		$cate = $pdl->select ();
		$this->assign ( 'cate', $cate );
		$this->display ();
	}
	// 更改产品多链接
	public function modify_product_download_link() {
		$this->is_login ();
		if ($this->isPost ()) {
			$id = isset ( $_POST ['id'] ) ? intval ( $_POST ['id'] ) : 0;
			$data ['pid'] = isset ( $_POST ['pid'] ) ? intval ( $_POST ['pid'] ) : 0;
			$data ['name'] = isset ( $_POST ['name'] ) ? trim ( $_POST ['name'] ) : '';
			$data ['url'] = isset ( $_POST ['url'] ) ? trim ( $_POST ['url'] ) : '';
			
			if (! $data ['pid'] || ! $data ['url']) {
				return;
			}
			$pdl = M ( 'ProductDownloadLink' );
			if ($pdl->where ( "pid=" . $data ['pid'] . " and name='" . $data ['name'] . "'" )->find ()) {
				echo "<script>alert('下载链接名已存在，请填写其他名字');history.back();</script>";
				return;
			}
			if ($pdl->where ( "id=$id" )->save ( $data )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/product_download_link_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$pdl = M ( 'ProductDownloadLink' );
			$p = M ( 'Product' );
			$data = $pdl->find ( $id );
			$this->assign ( 'data', $data );
			
			$cate = $p->where ( "one_download_link=0" )->select ();
			$this->assign ( 'pdata', $cate );
			$this->display ();
		}
	}
	// 删除产品多链接
	public function delete_product_download_link() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$pdl = M ( 'ProductDownloadLink' );
		$ret = $pdl->where ( "id=$id" )->delete ();
		if (! $ret) {
			echo $this->delete_fail;
			return;
		} else {
			echo $this->delete_success;
		}
	}
	// 添加文章分类
	public function article_classify() {
		$this->is_login ();
		if ($this->isPost ()) {
			$article_classify = M ( 'ArticleClassify' );
			
			$_POST ['add_time'] = time ();
			if (! $_POST ['classify_name'] || ! $_POST ['pid']) {
				return;
			}
			$updata = $this->up ( 0, 0 );
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 'bgimg') {
						$_POST ['bgimg'] = $v ['savename'];
					} elseif ($v ['key'] == 'img') {
						$_POST ['img'] = $v ['savename'];
					} elseif ($v ['key'] == 'new_art_img') {
						$data ['new_art_img'] = $v ['savename'];
					}
				}
			}
			if ($article_classify->where ( "pid=" . $_POST ['pid'] . " and classify_name='" . $_POST ['classify_name'] . "'" )->find ()) {
				echo "<script>alert('文章分类名已存在，请填写其他分类名');history.back();</script>";
				return;
			}
			if ($article_classify->add ( $_POST )) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/article_classify_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$bigcategory = M ( 'Bigcategory' );
			$pro = M ( 'Product' );
			$cate = $bigcategory->select ();
			$this->assign ( 'cate', $cate );
			$prodata = $pro->select ();
			$this->assign ( 'pdata', $prodata );
			$this->display ();
		}
	}
	// 文章分类管理
	public function article_classify_manage() {
		$this->is_login ();
		$article_classify = M ( 'ArticleClassify' );
		$cate = $article_classify->field ( 'think_article_classify.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->select ();
		$this->assign ( 'cate', $cate );
		$this->display ();
	}
	// 删除文章分类
	public function delete_article_classify() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$article_classify = M ( 'ArticleClassify' );
		$ret = $article_classify->where ( "id=$id" )->delete ();
		if (! $ret) {
			echo $this->delete_fail;
			return;
		} else {
			echo $this->delete_success;
		}
	}
	// 更改文章分类名称
	public function modify_article_classify() {
		$this->is_login ();
		if ($this->isPost ()) {
			$id = isset ( $_POST ['id'] ) ? intval ( $_POST ['id'] ) : 0;
			
			if (! $id || ! $_POST ['pid'] || ! $_POST ['classify_name']) {
				return;
			}
			$updata = $this->up ( 0, 0 );
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 'bgimg') {
						$_POST ['bgimg'] = $v ['savename'];
					} elseif ($v ['key'] == 'img') {
						$_POST ['img'] = $v ['savename'];
					} elseif ($v ['key'] == 'new_art_img') {
						$_POST ['new_art_img'] = $v ['savename'];
					}
				}
			}
			$article_classify = M ( 'ArticleClassify' );
			if ($article_classify->where ( "id=$id" )->save ( $_POST )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/article_classify_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$article_classify = M ( 'ArticleClassify' );
			$pro = M ( 'Product' );
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$data = $article_classify->field ( 'think_article_classify.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->where ( 'think_article_classify.id=' . $id )->find ();
			$this->assign ( 'art_classify', $data );
			$prodata = $pro->select ();
			$this->assign ( 'pdata', $prodata );
			$this->display ();
		}
	}
	// 静态化单个文章分类页
	public function article_classify_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$ac = M ( 'ArticleClassify' );
		$data = $ac->find ( $id );
		
		if (! $data ['statice_name']) {
			echo $this->art_no_statice_name;
			return;
		}
		$p = file_get_contents ( $this->root_name . '/Index/howto/id/' . $id . '/pid/' . $data ['pid'] );
		
		if (file_put_contents ( $data ['statice_name'] . '.html', $p )) {
			$ac->where ( 'id=' . $id )->save ( array (
					'is_statice' => '1' 
			) );
			echo $this->statice_success;
			return;
		} else {
			echo $this->statice_fail;
		}
	}
	// 删除静态化文章分类页
	public function delete_article_classify_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$article_classify = M ( 'ArticleClassify' );
		$pdata = $article_classify->find ( $id );
		// 删除相关静态化文件
		if (file_exists ( $pdata ['statice_name'] . '.html' )) {
			unlink ( $pdata ['statice_name'] . '.html' );
		} else {
			echo $this->file_noexist;
			return;
		}
		$data ['is_statice'] = 0;
		if ($article_classify->where ( "id=$id" )->save ( $data )) {
			echo $this->dele_statice_success;
			return;
		} else {
			echo $this->dele_statice_fail;
			return;
		}
	}
	
	// 栏目管理
	public function plate_manage() {
		$this->is_login ();
		$bigcategory = M ( 'Bigcategory' );
		$cate = $bigcategory->select ();
		// $plate=M('Plate');
		// $plate=$plate->select();
		$product = M ( 'Product' );
		$article = M ( 'Article' );
		foreach ( $cate as $k => $v ) {
			$cate [$k] ['art_num'] = $article->where ( 'pid=' . $v ['id'] )->count ();
			$cate [$k] ['pro_num'] = $product->where ( 'pid=' . $v ['id'] )->count ();
		}
		$this->assign ( 'cate', $cate );
		// $this->assign('plate',$plate);
		$this->display ();
	}
	// 更改大类名称
	public function change_big_cate() {
		$this->is_login ();
		if ($this->isPost ()) {
			$id = isset ( $_POST ['cate_id'] ) ? intval ( $_POST ['cate_id'] ) : 0;
			
			if (! $id || ! $_POST ['big_category_name']) {
				return;
			}
			$bigcategory = M ( 'Bigcategory' );
			// if($bigcategory->where("id!=".$id." and
			// big_category_name='".$data['big_category_name']."'")->find()){
			// echo "<script>alert('分类名已存在，请填写其他分类名');history.back();</script>";
			// return;
			// }
			
			$updata = $this->up ();
			if ($updata) {
				$_POST ['big_img'] = $updata [0] ['savename'];
			}
			if ($bigcategory->where ( "id=$id" )->save ( $_POST )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/plate_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$bigcategory = M ( 'Bigcategory' );
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$data = $bigcategory->find ( $id );
			$this->assign ( 'cate', $data );
			$this->display ();
		}
	}
	// 更改栏目名称
	public function modify_plate() {
		$this->is_login ();
		if ($this->isPost ()) {
			$pid = isset ( $_POST ['pid'] ) ? intval ( $_POST ['pid'] ) : 0;
			$id = isset ( $_POST ['plate_id'] ) ? intval ( $_POST ['plate_id'] ) : 0;
			$plate_name = isset ( $_POST ['change_name'] ) ? trim ( $_POST ['change_name'] ) : '';
			$plate_title = isset ( $_POST ['plate_title'] ) ? trim ( $_POST ['plate_title'] ) : '';
			$plate_keyword = isset ( $_POST ['plate_keyword'] ) ? trim ( $_POST ['plate_keyword'] ) : '';
			
			if (! $id || ! $plate_name) {
				return;
			}
			$plate = M ( 'Plate' );
			$data ['plate_name'] = $plate_name;
			$data ['plate_title'] = $plate_title;
			$data ['win_mac_classfy'] = isset ( $_POST ['win_mac_classfy'] ) ? trim ( $_POST ['win_mac_classfy'] ) : '1';
			if ($plate->where ( "id!=" . $id . " and pid=" . $pid . " and plate_name='" . $plate_name . "'" )->find ()) {
				echo "<script>alert('此分类栏目名已存在，请填写其他栏目名');history.back();</script>";
				return;
			}
			if ($plate_keyword) {
				$data ['plate_keyword'] = $plate_keyword;
			}
			if (isset ( $_POST ['plate_dis'] ) && $_POST ['plate_dis'] != '') {
				$data ['plate_description'] = isset ( $_POST ['plate_dis'] ) ? trim ( $_POST ['plate_dis'] ) : '';
			}
			$data ['statice_name'] = isset ( $_POST ['statice_name'] ) ? trim ( $_POST ['statice_name'] ) : '';
			if ($plate->where ( "id=$id" )->save ( $data )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/plate_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$plate = M ( 'Plate' );
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$data = $plate->find ( $id );
			$this->assign ( 'plate', $data );
			$this->display ();
		}
	}
	
	// 删除静态化文件 传入一个数组
	function delete_statice_file($arr) {
		if (is_array ( $arr )) {
			foreach ( $arr as $k => $v ) {
				if ($v ['statice_name'] && file_exists ( $v ['statice_name'] . '.html' )) {
					unlink ( $v ['statice_name'] . '.html' );
				}
			}
		}
	}
	
	// 删除大类
	public function delete_big_cate() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		
		$bigcategory = M ( 'Bigcategory' );
		$plate = M ( 'Plate' );
		$article = M ( 'Article' );
		$product = M ( 'Product' );
		$bdata = $bigcategory->find ( $id );
		$pdata = $plate->where ( 'pid=' . $id )->select ();
		$prodata = $product->where ( 'gid=' . $id )->select ();
		$adata = $article->where ( 'gid=' . $id )->select ();
		
		// 删除大类同时删除相关静态化文件
		if ($bdata ['statice_name'] && file_exists ( $bdata ['statice_name'] . '.html' )) {
			unlink ( $bdata ['statice_name'] . '.html' );
		}
		$this->delete_statice_file ( $pdata );
		$this->delete_statice_file ( $prodata );
		$this->delete_statice_file ( $adata );
		
		$bret = $bigcategory->where ( "id=$id" )->delete ();
		$pret = $plate->where ( "pid=$id" )->delete ();
		$aret = $article->where ( "gid=$id" )->delete ();
		$prret = $product->where ( "gid=$id" )->delete ();
		if (! $bret) {
			// echo "<script>alert('删除大类失败');history.back();</script>";
			echo $this->delete_fail;
			return;
		} else {
			// echo
			// "<script>alert('删除大类成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->delete_success;
			return;
		}
	}
	
	// 删除栏目
	public function delete_plate() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$plate = M ( 'Plate' );
		$article = M ( 'Article' );
		$product = M ( 'Product' );
		
		$pdata = $plate->find ( $id );
		$prodata = $product->where ( 'pid=' . $id )->select ();
		$adata = $article->where ( 'pid=' . $id )->select ();
		
		// 删除大类同时删除相关静态化文件
		if ($pdata ['statice_name'] && file_exists ( $pdata ['statice_name'] . '.html' )) {
			unlink ( $pdata ['statice_name'] . '.html' );
		}
		$this->delete_statice_file ( $prodata );
		$this->delete_statice_file ( $adata );
		
		$pret = $plate->where ( "id=$id" )->delete ();
		$aret = $article->where ( "pid=$id" )->delete ();
		$prret = $product->where ( "pid=$id" )->delete ();
		if (! $pret) {
			// echo "<script>alert('删除栏目失败');history.back();</script>";
			echo $this->delete_fail;
			return;
		} else {
			echo $this->delete_success;
			return;
			// echo
			// "<script>alert('删除栏目成功');location.href='".__URL__."/plate_manage';</script>";
		}
	}
	
	// 产品管理
	public function product_manage() {
		$this->is_login ();
		$product = M ( 'Product' );
		$bigcategory = M ( 'Bigcategory' );
		$plate = M ( 'Plate' );
		$cate = $bigcategory->select ();
		$this->assign ( 'cate', $cate );
		$pid = $_GET ['pid'];
		if (isset ( $pid ) && $pid != '') {
			$pdata = $product->where ( 'pid=' . $pid )->select ();
			$this->assign ( 'b_id', $pid );
		} else {
			$pdata = $product->select ();
		}
		foreach ( $pdata as $k => $v ) {
			$pdata [$k] ['cate_data'] = $bigcategory->where ( 'id=' . $v ['pid'] )->find ();
			// $pdata[$k]['plate_data']=$plate->where('id='.$v['pid'])->find();
		}
		$this->assign ( 'product', $pdata );
		$this->display ();
	}
	// 删除产品
	public function delete_product() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$product = M ( 'Product' );
		$pdata = $product->find ( $id );
		// 删除大类同时删除相关静态化文件
		if ($pdata ['statice_name'] && file_exists ( $pdata ['statice_name'] . '.html' )) {
			unlink ( $pdata ['statice_name'] . '.html' );
		}
		$ret = $product->where ( "id=$id" )->delete ();
		if (! $ret) {
			echo $this->delete_fail;
		} else {
			echo $this->delete_success;
		}
	}
	// 修改产品信息
	public function modify_product() {
		$this->is_login ();
		if ($this->isPost ()) {
			$product = M ( 'Product' );
			$id = isset ( $_POST ['product_id'] ) ? intval ( $_POST ['product_id'] ) : 0;
			;
			$_POST ['relative_product'] = isset ( $_POST ['rp'] ) ? trim ( $_POST ['rp'], ',' ) : '';
			
			if (get_magic_quotes_gpc ()) {
				$_POST ['content'] = isset ( $_POST ['product_content'] ) ? stripslashes ( $_POST ['product_content'] ) : '';
				$_POST ['sec_description'] = isset ( $_POST ['sec_description'] ) ? stripslashes ( $_POST ['sec_description'] ) : '';
			} else {
				$_POST ['content'] = $_POST ['product_content'];
			}
			
			if (! $id || ! $_POST ['product_name']) {
				return;
			}
			if ($product->where ( "id!=" . $id . " and pid=" . $_POST ['pid'] . " and product_name='" . $_POST ['product_name'] . "'" )->find ()) {
				echo "<script>alert('产品名已存在，请填写其他产品名');history.back();</script>";
				return;
			}
			// if(!$_FILES){
			// return;
			// }
			$width = isset ( $_POST ['width'] ) ? trim ( $_POST ['width'] ) : 0;
			$height = isset ( $_POST ['height'] ) ? trim ( $_POST ['height'] ) : 0;
			$updata = $this->up ( $width, $height );
			
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 't_img') {
						$_POST ['product_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'sec_img') {
						$_POST ['sec_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'three_img') {
						$_POST ['three_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'pimg') {
						$_POST ['pimg'] = $v ['savename'];
					} elseif ($v ['key'] == 'small_icon') {
						$_POST ['small_icon'] = $v ['savename'];
					}
				}
				// $data['product_img']=$updata[0]['savename'];
			}
			if ($product->where ( "id=" . $id )->save ( $_POST )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/product_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$product = M ( 'Product' );
			$bigcategory = M ( 'Bigcategory' );
			$plate = M ( 'Plate' );
			$pdata = $product->where ( 'id=' . $id )->find ();
			
			$rpid = array ();
			if (! empty ( $pdata ['relative_product'] )) {
				$rpid = explode ( ',', $pdata ['relative_product'] );
			}
			$this->assign ( 'rpid', $rpid );
			$allpro = $product->field ( 'think_product.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_product.pid' )->order ( 'b.id' )->select ();
			foreach ( $allpro as $k => $v ) {
				if (in_array ( $v ['id'], $rpid )) {
					$allpro [$k] ['select'] = '1';
				}
			}
			$this->assign ( 'allpro', $allpro );
			
			$pdata ['cate_data'] = $bigcategory->where ( 'id=' . $pdata ['pid'] )->find ();
			// $pdata['plate_data']=$plate->where('id='.$pdata['pid'])->find();
			$this->assign ( 'product', $pdata );
			$art_classify = M ( "ArticleClassify" );
			$ac_data = $art_classify->field ( 'think_article_classify.*,b.big_category_name' )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->select ();
			$this->assign ( 'ac_data', $ac_data );
			$this->display ();
		}
	}
	
	// 文章管理
	public function article_manage() {
		$this->is_login ();
		$article = M ( 'Article' );
		$bigcategory = M ( 'Bigcategory' );
		$cate = $bigcategory->select ();
		$this->assign ( 'cate', $cate );
		$plate = M ( 'Plate' );
		$pid = $_GET ['pid'];
		if (isset ( $pid ) && $pid != '') {
			$adata = $article->where ( 'pid=' . $pid )->order ( 'pid' )->select ();
			$this->assign ( 'b_id', $pid );
		} else {
			$adata = $article->order ( 'pid' )->select ();
		}
		foreach ( $adata as $k => $v ) {
			$adata [$k] ['cate_data'] = $bigcategory->where ( 'id=' . $v ['pid'] )->find ();
			// $adata[$k]['plate_data']=$plate->where('id='.$v['pid'])->find();
		}
		$this->assign ( 'product', $adata );
		$this->display ();
	}
	// 删除文章
	public function delete_article() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$article = M ( 'Article' );
		$adata = $article->find ( $id );
		// 删除大类同时删除相关静态化文件
		if ($adata ['statice_name'] && file_exists ( $adata ['statice_name'] . '.html' )) {
			unlink ( $adata ['statice_name'] . '.html' );
		}
		$ret = $article->where ( "id=$id" )->delete ();
		if (! $ret) {
			// echo "<script>alert('删除文章失败');history.back();</script>";
			echo $this->delete_fail;
			return;
		} else {
			// echo
			// "<script>alert('删除文章成功');location.href='".__URL__."/article_manage';</script>";
			echo $this->delete_success;
		}
	}
	// 修改文章
	public function modify_article() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		if ($this->isPost ()) {
			$article = M ( 'Article' );
			$id = isset ( $_POST ['article_id'] ) ? intval ( $_POST ['article_id'] ) : 0;
			//
			if (get_magic_quotes_gpc ()) {
				$_POST ['content'] = isset ( $_POST ['content'] ) ? stripslashes ( $_POST ['content'] ) : '';
				$_POST ['author_des'] = isset ( $_POST ['author_des'] ) ? stripslashes ( $_POST ['author_des'] ) : '';
			}
			$updata = $this->up ( 0, 0 );
			if ($updata) {
				foreach ( $updata as $v ) {
					if ($v ['key'] == 'author_img') {
						$_POST ['author_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'right_img') {
						$_POST ['right_img'] = $v ['savename'];
					} elseif ($v ['key'] == 'small_icon') {
						$_POST ['small_icon'] = $v ['savename'];
					}
				}
			}
			if (! $id || ! $_POST ['title']) {
				return;
			}
			if ($article->where ( "id!=" . $id . " and pid=" . $_POST ['pid'] . " and title='" . $_POST ['title'] . "'" )->find ()) {
				echo "<script>alert('文章标题已存在，请填写其他文章标题');history.back();</script>";
				return;
			}
			if ($article->where ( "id=" . $id )->save ( $_POST )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/article_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$article = M ( 'Article' );
			$bigcategory = M ( 'Bigcategory' );
			$art_classify = M ( 'ArticleClassify' );
			$adata = $article->where ( 'id=' . $id )->find ();
			
			$adata ['cate_data'] = $bigcategory->where ( 'id=' . $adata ['pid'] )->find ();
			$adata ['ac_data'] = $art_classify->field ( 'think_article_classify.*,b.big_category_name' )->where ( 'b.id=' . $adata ['pid'] )->join ( 'left join think_bigcategory b on b.id=think_article_classify.pid' )->select ();
			$this->assign ( 'article', $adata );
			$this->display ();
		}
	}
	public function exit_login() {
		unset ( $_COOKIE ['login_name'] );
		unset ( $_SESSION ['login_name'] );
		echo "<script>location.href='" . __URL__ . "/index'</script>";
	}
	// 静态化文章页
	public function article_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		$plate_name = $_GET ['name'];
		if (! $id) {
			return;
		}
		$article = M ( 'Article' );
		// $plate=M('Plate');
		$data = $article->find ( $id );
		// $pdata=$plate->find($data['pid']);
		
		if (! $data ['statice_name']) {
			// echo
			// "<script>alert('文章添加静态化名称');location.href='".__URL__."/modify_article/id/".$id."';</script>";
			echo $this->art_no_statice_name;
			return;
		}
		// file_get_contents($this->root_name.__ROOT__.'/Index/howto/id/'.$pdata['pid'].'/type/select');
		$p = file_get_contents ( $this->root_name . '/Index/article/id/' . $id );
		
		if (file_put_contents ( $data ['statice_name'] . '.html', $p )) {
			$article->where ( 'id=' . $id )->save ( array (
					'is_statice' => '1' 
			) );
			// echo
			// "<script>alert('静态化成功');location.href='".__URL__."/article_manage';</script>";
			echo $this->statice_success;
			return;
		} else {
			// echo "<script>alert('静态化失败');history.back();</script>";
			echo $this->statice_fail;
		}
	}
	// 静态化全部文章页
	public function staticAllArticle() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$article = M ( 'Article' );
		if ($this->isPost ()) {
			$start_id = isset ( $_POST ['start_id'] ) ? intval ( $_POST ['start_id'] ) : 1;
			$end_id = isset ( $_POST ['end_id'] ) ? intval ( $_POST ['end_id'] ) : 1;
			$allArt = $article->where ( 'statice_name != "" and id>=' . $start_id . " and id<=" . $end_id )->select ();
			
			foreach ( $allArt as $v ) {
				$id = $v ['id'];
				if (! $id) {
					return;
				}
				
				if (! $v ['statice_name']) {
					continue;
				}
				
				$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/article/id/' . $id );
				if (file_put_contents ( $v ['statice_name'] . '.html', $p )) {
					$article->where ( 'id=' . $id )->save ( array (
							'is_statice' => '1' 
					) );
				} else {
					echo "<script>alert('静态化失败');history.back();</script>";
				}
			}
			echo "<script>alert('静态化成功');location.href='" . __URL__ . "/staticAllArticle';</script>";
		} else {
			$id = $article->field ( "id" )->limit ( 1 )->order ( 'id desc' )->find ();
			$this->assign ( "id", $id );
			$this->display ();
		}
	}
	// 静态化产品页
	public function product_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$product = M ( 'Product' );
		$data = $product->find ( $id );
		if (! $data ['statice_name']) {
			// echo
			// "<script>alert('请先为产品添加静态化名称');location.href='".__URL__."/modify_product/id/".$id."';</script>";
			echo $this->pro_no_statice_name;
			return;
		}
		$p = file_get_contents ( $this->root_name . '/Index/product_description/id/' . $id );
		if (file_put_contents ( $data ['statice_name'] . '.html', $p )) {
			$product->where ( 'id=' . $id )->save ( array (
					'is_statice' => '1' 
			) );
			// echo
			// "<script>alert('静态化成功');location.href='".__URL__."/product_manage';</script>";
			echo $this->statice_success;
		} else {
			// echo "<script>alert('静态化失败');history.back();</script>";
			echo $this->statice_fail;
		}
	}
	// 静态化全部产品页
	public function staticAllProduct() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$product = M ( 'Product' );
		if ($this->isPost ()) {
			$start_id = isset ( $_POST ['start_id'] ) ? intval ( $_POST ['start_id'] ) : 1;
			$end_id = isset ( $_POST ['end_id'] ) ? intval ( $_POST ['end_id'] ) : 1;
			$allPro = $product->where ( 'statice_name != "" and id>=' . $start_id . ' and id<=' . $end_id )->select ();
			
			foreach ( $allPro as $v ) {
				$id = $v ['id'];
				if (! $id) {
					return;
				}
				
				if (empty ( $v ['statice_name'] )) {
					continue;
				}
				
				$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/product_description/id/' . $id );
				if (file_put_contents ( "./" . $v ['statice_name'] . '.html', $p )) {
					$product->where ( 'id=' . $id )->save ( array (
							'is_statice' => '1' 
					) );
				} else {
					echo "<script>alert('静态化失败');history.back();</script>";
				}
			}
			echo "<script>alert('静态化成功');location.href='" . __URL__ . "/staticAllProduct';</script>";
		} else {
			$id = $product->field ( "id" )->limit ( 1 )->order ( 'id desc' )->find ();
			$this->assign ( "id", $id );
			$this->display ();
		}
	}
	// 静态化栏目页
	public function plate_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		$pid = $_GET ['pid'];
		if (! $id || ! $pid) {
			return;
		}
		$plate = M ( 'Plate' );
		$data = $plate->find ( $id );
		if (! $data ['statice_name']) {
			// echo
			// "<script>alert('请先为栏目添加静态化名称');location.href='".__URL__."/modify_plate/pid/".$pid."/id/".$id."';</script>";
			echo $this->plate_no_statice_name;
			return;
		}
		$p = file_get_contents ( $this->root_name . '/Index/classify/id/' . $id );
		if (file_put_contents ( $data ['statice_name'] . '.html', $p )) {
			$plate->where ( 'id=' . $id )->save ( array (
					'is_statice' => '1' 
			) );
			// echo
			// "<script>alert('静态化成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->statice_success;
			return;
		} else {
			// echo "<script>alert('静态化失败');history.back();</script>";
			echo $this->statice_fail;
			return;
		}
	}
	
	// 静态化全部栏目（二级）
	public function staticeAllPlate() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$plate = M ( 'Plate' );
		// $data=$plate->where('statice_name != ""')->select();
		$data = $plate->field ( 'think_plate.*,b.big_category_name  as bname' )->join ( 'left join think_bigcategory b on b.id=think_plate.pid' )->where ( 'think_plate.statice_name != ""' )->select ();
		foreach ( $data as $v ) {
			$id = $v ['id'];
			if (! $id) {
				return;
			}
			if (empty ( $v ['statice_name'] )) {
				continue;
			}
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/classify/id/' . $id );
			if (file_put_contents ( "./" . $v ['bname'] . "/" . $v ['statice_name'] . '.html', $p )) {
				$plate->where ( 'id=' . $id )->save ( array (
						'is_statice' => '1' 
				) );
			} else {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');location.href='" . __URL__ . "/plate_manage';</script>";
	}
	
	// 静态化howto页
	public function howto_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$bigcategory = M ( 'Bigcategory' );
		$data = $bigcategory->find ( $id );
		if (! $data ['statice_name']) {
			// echo
			// "<script>alert('请先为大类添加howto页静态化名称');location.href='".__URL__."/change_big_cate/id/".$id."';</script>";
			echo $this->howto_no_statice_name;
			return;
		}
		$p = file_get_contents ( $this->root_name . '/Index/howto/id/' . $id . '/type/select' );
		if (file_put_contents ( $data ['statice_name'] . '.html', $p )) {
			$bigcategory->where ( 'id=' . $id )->save ( array (
					'is_statice' => '1' 
			) );
			// echo
			// "<script>alert('静态化成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->statice_success;
			return;
		} else {
			// echo "<script>alert('静态化失败');history.back();</script>";
			echo $this->statice_fail;
		}
	}
	
	// 静态化全部howto页
	public function staticeAllHowto() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$bigcategory = M ( 'Bigcategory' );
		$data = $bigcategory->where ( 'statice_name != ""' )->select ();
		foreach ( $data as $v ) {
			$id = $v ['id'];
			if (! $id) {
				return;
			}
			if (empty ( $v ['statice_name'] )) {
				continue;
			}
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/howto/id/' . $id . '/type/select' );
			if (file_put_contents ( "./" . $v ['statice_name'] . '.html', $p )) {
				$bigcategory->where ( 'id=' . $id )->save ( array (
						'is_statice' => '1' 
				) );
			} else {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');location.href='" . __URL__ . "/plate_manage';</script>";
	}
	// 静态化文章大类
	public function staticeAllTutorials() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$ac = M ( 'ArticleClassify' );
		$data = $ac->where ( "statice_name != ''" )->select ();
		
		foreach ( $data as $v ) {
			$id = $v ['id'];
			$pid = $v ['pid'];
			if (! $id) {
				return;
			}
			if (empty ( $v ['statice_name'] )) {
				continue;
			}
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/howto/id/' . $id . '/pid/' . $pid );
			if (file_put_contents ( "./" . $v ['statice_name'] . '.html', $p )) {
				$ac->where ( 'id=' . $id )->save ( array (
						'is_statice' => '1' 
				) );
			} else {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');location.href='" . __URL__ . "/article_classify_manage';</script>";
	}
	// 静态化resources
	public function staticeAllResources() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$ac = M ( 'ArticleClassify' );
		$data = $ac->where ( "statice_name != ''" )->select ();
		
		foreach ( $data as $v ) {
			$id = $v ['id'];
			if (! $id) {
				return;
			}
			if (empty ( $v ['statice_name'] )) {
				continue;
			}
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/resources/id/' . $id );
			if (file_put_contents ( "./" . $v ['statice_name'] . '.html', $p )) {
				$ac->where ( 'id=' . $id )->save ( array (
						'is_statice' => '1' 
				) );
			} else {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');location.href='" . __URL__ . "/article_classify_manage';</script>";
	}
	// 静态化全部一级大类页
	public function staticeAllBig() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$bigcategory = M ( 'Bigcategory' );
		$data = $bigcategory->select ();
		foreach ( $data as $v ) {
			$id = $v ['id'];
			if (! $id) {
				return;
			}
			if (empty ( $v ['big_category_name'] )) {
				continue;
			}
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/product/id/' . $id );
			if (! file_put_contents ( "./" . strtolower ( $v ['big_category_name'] ) . '-software.html', $p )) {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');location.href='" . __URL__ . "/plate_manage';</script>";
	}
	
	// 删除howto静态化页面
	Public function delete_howto_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$bigcategory = M ( 'Bigcategory' );
		$bdata = $bigcategory->find ( $id );
		
		// 删除相关静态化文件
		if ($bdata ['statice_name'] && file_exists ( $bdata ['statice_name'] . '.html' )) {
			unlink ( $bdata ['statice_name'] . '.html' );
		} else {
			// echo "<script>alert('静态化文件不存在');history.back();</script>";
			echo $this->file_noexist;
			return;
		}
		$data ['is_statice'] = 0;
		if ($bigcategory->where ( "id=$id" )->save ( $data )) {
			// echo
			// "<script>alert('删除成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->dele_statice_success;
			return;
		} else {
			// echo "<script>alert('删除失败');history.back();</script>";
			echo $this->dele_statice_fail;
		}
	}
	
	// 删除静态化栏目页
	public function delete_plate_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		$pid = $_GET ['pid'];
		if (! $id || ! $pid) {
			return;
		}
		$plate = M ( 'Plate' );
		$pdata = $plate->find ( $id );
		// 删除相关静态化文件
		if ($pdata ['statice_name'] && file_exists ( $pdata ['statice_name'] . '.html' )) {
			unlink ( $pdata ['statice_name'] . '.html' );
		} else {
			// echo "<script>alert('静态化文件不存在');history.back();</script>";
			echo $this->file_noexist;
			return;
		}
		$data ['is_statice'] = 0;
		if ($plate->where ( "id=$id" )->save ( $data )) {
			// echo
			// "<script>alert('删除成功');location.href='".__URL__."/plate_manage';</script>";
			echo $this->dele_statice_success;
			return;
		} else {
			// echo "<script>alert('删除失败');history.back();</script>";
			echo $this->dele_statice_fail;
			return;
		}
	}
	
	// 删除产品静态化栏目页
	public function delete_product_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$product = M ( 'Product' );
		$pdata = $product->find ( $id );
		// 删除相关静态化文件
		if ($pdata ['statice_name'] && file_exists ( $pdata ['statice_name'] . '.html' )) {
			unlink ( $pdata ['statice_name'] . '.html' );
		} else {
			echo $this->file_noexist;
			return;
		}
		$data ['is_statice'] = 0;
		if ($product->where ( "id=$id" )->save ( $data )) {
			echo $this->dele_statice_success;
			return;
		} else {
			echo $this->dele_statice_fail;
			return;
		}
	}
	// 删除文章静态化栏目页
	public function delete_article_statice() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$article = M ( 'Article' );
		$adata = $article->find ( $id );
		// 删除相关静态化文件
		if ($adata ['statice_name'] && file_exists ( $adata ['statice_name'] . '.html' )) {
			unlink ( $adata ['statice_name'] . '.html' );
		} else {
			echo $this->file_noexist;
			return;
		}
		$data ['is_statice'] = 0;
		if ($article->where ( "id=$id" )->save ( $data )) {
			echo $this->dele_statice_success;
			return;
		} else {
			echo $this->dele_statice_fail;
			return;
		}
	}
	
	// 生产网站地图
	public function sitemap() {
		$this->is_login ();
		$html = '<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="' . $this->site_root . '/sitemap.xsl"?>';
		$html .= '<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
		$webUrl = $this->site_root . '/';
		$html .= $this->url ( $webUrl, date ( 'c', time () ), 'monthly', '1.0' );
		$article = M ( 'Article' );
		$product = M ( 'Product' );
		$adata = $article->where ( "statice_name != '' and is_statice=1" )->select ();
		$pdata = $product->where ( "statice_name != '' and is_statice=1" )->select ();
		foreach ( $adata as $k => $v ) {
			$html .= $this->url ( $webUrl . $v ['statice_name'] . ".html", date ( 'c', $v ['add_time'] ), 'monthly', '1' );
		}
		foreach ( $pdata as $k => $v ) {
			$html .= $this->url ( $webUrl . $v ['statice_name'] . ".html", date ( 'c', $v ['add_time'] ), 'monthly', '1' );
		}
		$html .= '</urlset>';
		file_put_contents ( 'sitemap.xml', $html );
		echo "<script>alert('生产网站地图成功');history.go(-1);</script>";
	}
	public function url($loc, $lastmod, $changefreq, $priority) {
		$html = '<url>
	　　			  <loc>' . $loc . '</loc>
				　<lastmod>' . $lastmod . '</lastmod>
				　<changefreq>' . $changefreq . '</changefreq>
				　<priority>' . $priority . '</priority>
			　</url> ';
		return $html;
	}
	public function staticeBuy() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$product = M ( 'Product' );
		$allPro = $product->where ( 'statice_name != ""' )->select ();
		
		foreach ( $allPro as $v ) {
			$id = $v ['id'];
			if (! $id) {
				return;
			}
			
			if (empty ( $v ['statice_name'] )) {
				continue;
			}
			
			$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/buy/id/' . $id );
			if (! file_put_contents ( "./purchasing/" . $v ['statice_name'] . '.html', $p )) {
				echo "<script>alert('静态化失败');history.back();</script>";
			}
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeDownload() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$product = M ( 'Product' );
		if ($this->isPost ()) {
			$start_id = isset ( $_POST ['start_id'] ) ? intval ( $_POST ['start_id'] ) : 1;
			$end_id = isset ( $_POST ['end_id'] ) ? intval ( $_POST ['end_id'] ) : 1;
			$allPro = $product->where ( 'statice_name != "" and id>=' . $start_id . ' and id<=' . $end_id )->select ();
			
			foreach ( $allPro as $v ) {
				$id = $v ['id'];
				$pid = $v ['pid'];
				if (! $id || ! $pid) {
					return;
				}
				
				if (empty ( $v ['statice_name'] )) {
					continue;
				}
				
				$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/download/id/' . $id . '/pid/' . $pid );
				if (! file_put_contents ( "./downloading/" . $v ['statice_name'] . '.html', $p )) {
					echo "<script>alert('静态化失败');history.back();</script>";
				}
			}
			echo "<script>alert('静态化成功');history.back();;</script>";
		} else {
			$id = $product->field ( "id" )->limit ( 1 )->order ( 'id desc' )->find ();
			$this->assign ( "id", $id );
			$this->display ();
		}
	}
	public function staticeContactUs() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/contactUs' );
		if (! file_put_contents ( 'contact-us.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeTermsConditions() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/termsConditions' );
		if (! file_put_contents ( 'terms-conditions.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticePrivacyPolicy() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/privacyPolicy' );
		if (! file_put_contents ( 'privacy-policy.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeAboutUs() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/aboutUs' );
		if (! file_put_contents ( 'about-us.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeLinks() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/links' );
		if (! file_put_contents ( 'links.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeAllProduct() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/allproduct' );
		if (! file_put_contents ( 'product.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeAllDownload() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/alldownload' );
		if (! file_put_contents ( 'download.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function staticeSupport() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/support' );
		if (! file_put_contents ( 'support.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function footlink() {
		$this->display ();
	}
	// 产品下载购买信息
	public function product_download_buy_info() {
		$this->is_login ();
		$bigcategory = M ( 'Bigcategory' );
		$cate = $bigcategory->select ();
		$this->assign ( 'cate', $cate );
		// $plate=M('Plate');
		// $plate=$plate->select();
		// $this->assign('plate',$plate);
		$dy = M ( 'DownloadBuy' );
		$where = ' 1=1 ';
		if (! empty ( $_POST ['t_time'] ) && ! empty ( $_POST ['e_time'] )) {
			$where .= " and think_download_buy.time >= '" . $_POST ['t_time'] . "' and think_download_buy.time <= '" . $_POST ['e_time'] . "' ";
		} else {
			$where .= " and think_download_buy.time = '" . date ( 'Y-m-d' ) . "' ";
		}
		$this->assign ( 's_time', $_POST ['t_time'] );
		$this->assign ( 'e_time', $_POST ['e_time'] );
		if (! empty ( $_POST ['plate'] )) {
			$cid = $_POST ['plate'];
			$where .= " and b.id = $cid";
			$this->assign ( 'b_id', $cid );
		}
		$pdata = $dy->field ( 'think_download_buy.*,sum(think_download_buy.down_num) as d_num,sum(think_download_buy.buy_num) as b_num,pro.product_name,b.big_category_name' )->join ( 'left join think_product pro on pro.id=think_download_buy.pid left join think_bigcategory b on b.id=pro.pid' )->group ( 'think_download_buy.pid' )->where ( $where )->select ();
		$this->assign ( 'product', $pdata );
		$this->display ();
	}
	public function down_buy_link() {
		$this->is_login ();
		$product = M ( 'Product' );
		$bigcategory = M ( 'Bigcategory' );
		$plate = M ( 'Plate' );
		$pid = $_GET ['pid'];
		
		$this->assign ( 'host', 'http://' . $_SERVER ['HTTP_HOST'] );
		if ($_GET ['link'] == 2) {
			$pdata = $product->field ( 'think_product.*,pdl.id as pdlid, pdl.name as pdlname,pdl.url as pdlurl' )->join ( 'think_product_download_link pdl on pdl.pid=think_product.id' )->where ( 'think_product.one_download_link=0' )->select ();
		} else {
			if (isset ( $pid ) && $pid != '') {
				$pdata = $product->where ( 'pid=' . $pid . ' and one_download_link=1' )->select ();
			} else {
				$pdata = $product->where ( 'one_download_link=1' )->select ();
			}
		}
		foreach ( $pdata as $k => $v ) {
			$pdata [$k] ['cate_data'] = $bigcategory->where ( 'id=' . $v ['pid'] )->find ();
			// $pdata[$k]['plate_data']=$plate->where('id='.$v['pid'])->find();
		}
		$this->assign ( 'link', $_GET ['link'] );
		$this->assign ( 'product', $pdata );
		$this->display ();
	}
	public function staticeSearchResult() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$p = file_get_contents ( $this->root_name . __ROOT__ . '/Index/search_result' );
		if (! file_put_contents ( 'search_result.html', $p )) {
			echo "<script>alert('静态化失败');history.back();</script>";
		}
		echo "<script>alert('静态化成功');history.back();;</script>";
	}
	public function hotTag() {
		$this->is_login ();
		if ($this->isPost ()) {
			$data ['tag_name'] = isset ( $_POST ['tag_name'] ) ? trim ( $_POST ['tag_name'] ) : '';
			$data ['tag_url'] = isset ( $_POST ['tag_url'] ) ? trim ( $_POST ['tag_url'] ) : '';
			if (! $data ['tag_name'] || ! $data ['tag_url']) {
				exit ( '标签名和链接不能为空' );
			}
			$ht = M ( 'HotTag' );
			if ($ht->where ( "tag_name='" . $data ['tag_name'] . "' and tag_url='" . $data ['tag_url'] . "'" )->find ()) {
				echo "<script>alert('标签名已存在，请填写其他标签名');history.back();</script>";
				return;
			}
			if ($ht->add ( $data )) {
				echo "<script>alert('添加成功');location.href='" . __URL__ . "/hot_tag_manage';</script>";
			} else {
				echo "<script>alert('添加失败');history.back();</script>";
			}
		} else {
			$this->display ();
		}
	}
	// hotTag管理
	public function hot_tag_manage() {
		$this->is_login ();
		$ht = M ( 'HotTag' );
		$cate = $ht->select ();
		$this->assign ( 'cate', $cate );
		$this->display ();
	}
	// 更改hotTag名称
	public function modify_hot_tag() {
		$this->is_login ();
		if ($this->isPost ()) {
			$id = isset ( $_POST ['id'] ) ? intval ( $_POST ['id'] ) : 0;
			$data ['tag_name'] = isset ( $_POST ['tag_name'] ) ? trim ( $_POST ['tag_name'] ) : '';
			$data ['tag_url'] = isset ( $_POST ['tag_url'] ) ? trim ( $_POST ['tag_url'] ) : '';
			if (! $data ['tag_name'] || ! $data ['tag_url']) {
				exit ( '标签名和链接不能为空' );
			}
			$ht = M ( 'HotTag' );
			if ($ht->where ( "tag_name='" . $data ['tag_name'] . "' and tag_url='" . $data ['tag_url'] . "'" )->find ()) {
				echo "<script>alert('标签名已存在，请填写其他标签名');history.back();</script>";
				return;
			}
			if ($ht->where ( "id=$id" )->save ( $data )) {
				echo "<script>alert('修改成功');location.href='" . __URL__ . "/hot_tag_manage';</script>";
			} else {
				echo "<script>alert('修改失败');history.back();</script>";
			}
		} else {
			$ht = M ( 'HotTag' );
			$id = $_GET ['id'];
			if (! $id) {
				return;
			}
			$data = $ht->where ( 'id=' . $id )->find ();
			$this->assign ( 'ht', $data );
			$this->display ();
		}
	}
	// 删除hotTag
	public function delete_hot_tag() {
		header ( "Content-Type:text/html; charset=utf-8" );
		$this->is_login ();
		$id = $_GET ['id'];
		if (! $id) {
			return;
		}
		$ht = M ( 'HotTag' );
		$ret = $ht->where ( "id=$id" )->delete ();
		if (! $ret) {
			echo $this->delete_fail;
			return;
		} else {
			echo $this->delete_success;
		}
	}
	function changeSort() {
		$val = $_POST ['val'];
		$id = $_POST ['id'];
		$type = $_POST ['type'];
		if ($type == 'all') {
			$sort ['sortall'] = $val;
		} elseif ($type == 'p') {
			$sort ['psort'] = $val;
		}
		$product = M ( 'Product' );
		if ($product->where ( "id=" . $id )->save ( $sort )) {
			echo 1;
		} else {
			echo 0;
		}
	}
	function changeAsort() {
		$val = $_POST ['val'];
		$id = $_POST ['id'];
		$art = M ( 'Article' );
		$sort ['asort'] = $val;
		if ($art->where ( "id=" . $id )->save ( $sort )) {
			echo 1;
		} else {
			echo 0;
		}
	}
}
?>